package com.xunhang.controller;

import com.xunhang.dto.Result;
import com.xunhang.entity.Admin;
import com.xunhang.service.impl.AdminService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpSession;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin")
@Tag(name = "管理员模块")
@CrossOrigin(origins = "*")
public class AdminController {

    @Autowired
    AdminService adminService;
    @Operation(summary = "管理员登录接口",description = "管理员登录,返回一个token，放到httpheader authorization")
    @PostMapping("/login")
    public Result login(@RequestBody Admin admin, HttpSession httpSession){
        return adminService.login(admin);
    }
    @Operation(summary = "管理员登出接口",description = "管理员登出")
    @PostMapping("/logout")
    public Result logout(){
        return adminService.logout();
    }
    @Operation(summary = "管理员注册接口",description = "管理员注册")
    @PostMapping("/register")
    public Result register(@RequestBody Admin admin, HttpSession httpSession){
        return adminService.register(admin);
    }
}
